import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @Author YuanYuan
 * @Date 2022/11/28
 * @Time 14:33
 */
@WebServlet("/cancellation")
public class CancellationServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession httpSession = req.getSession(false);
        if(null == httpSession) {
            resp.setContentType("text/html; charset=utf8");
            resp.getWriter().write("错误");
            return;
        }
        if(null == httpSession.getAttribute("user")) {
            resp.setContentType("text/html; charset=utf8");
            resp.getWriter().write("错误");
            return;
        }
        httpSession.removeAttribute("user");

        resp.setStatus(302);
        resp.sendRedirect("login.html");
    }
}
